﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WarOfDev.EF;
using WarOfDev.Web.ViewModels;

namespace WarOfDev.Web.Models.MappingToViewModel
{
    public static class ModuleMapping
    {
        public static void BaseToViewModel(ModuleViewModel vm, Module model)
        {
            vm.ParentId = model.ParentId;
            vm.ModuleName = model.ModuleName;
            vm.Description = model.Description;

            vm.Id = model.Id;
            vm.IsLocked = model.IsLocked;
            vm.ModifiedBy = model.ModifiedBy;
            vm.ModifiedOn = model.ModifiedOn;
            vm.CreatedBy = model.CreatedBy;
            vm.CreatedOn = model.CreatedOn;
        }

        public static ModuleViewModel ToViewModel(this Module model)
        {
            var vm = new ModuleViewModel();
            if (model != null)
            {
                BaseToViewModel(vm, model);
            }

            return vm;

        }

        public static ModuleViewModel ToViewModel(this Module model, Module parent)
        {
            var vm = new ModuleViewModel();
            if (model != null)
            {
                BaseToViewModel(vm, model);
                vm.Parent = parent.ToViewModel();
            }

            return vm;
        }

        public static ModuleViewModel ToViewModel(this Module model, Module parent, bool hasChild)
        {
            var vm = new ModuleViewModel();
            if (model != null)
            {
                BaseToViewModel(vm, model);
                vm.Parent = parent.ToViewModel();
                vm.HasChild = hasChild;
            }

            return vm;
        }
    }
}